<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>pod列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script type="text/javascript" src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/js/xkube.js?v=1" charset="utf-8"></script>
    <script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<style type="text/css">
  .layui-table-cell {
    height: auto;
    line-height: 15px !important;
    text-overflow: inherit;
    overflow: ellipsis;
    white-space: normal;
  }
  .layui-table-cell .layui-table-tool-panel li {
    word-break: break-word;
  }
</style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-table" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-sm" lay-event="podLog">日志</a>
            <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="terminal">终端</a>
        </script>
    </div>
</div>
</body>

<script type="text/html" id="TagTpl">
    {{# if (d.labels != "") { }}
            {{# layui.each(d.labels.split(','), function(index, item){ }}
                {{# if(index == 0) { }}
                        <span>{{ item }}</span>
                {{# }else{ }}
                        <br><span>{{ item }}</span>
                {{# } }}  
            {{# });  }}
    {{# }else{  }}
            <span></span>
    {{# } }}
</script>	

<script type="text/html" id="podPhaseTpl">
  {{# if ( d.podPhase == 'Running' ) { }}
     <span style="color:#218868">{{ d.podPhase}}</span>
  {{# } else if ( d.podPhase == 'Succeeded' ) { }}
     <span style="color:#1E9FFF">{{ d.podPhase}}</span>
	{{# } else { }}
    <span style="color:#FF5722">{{ d.podPhase}}</span>
{{# } }}
</script>

<script>
var clusterId = getQueryString("clusterId");
if (clusterId == null) {
	clusterId = getCookie("clusterId")
}
    layui.use(['form', 'table','miniTab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
            miniTab = layui.miniTab,
            miniTab.listen();

            form.render();

        table.render({
            elem: '#currentTableId',
            url: '/pod/v1/List?clusterId='+clusterId,
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            parseData: function(res) { //实现加载全部数据后再分页
            	if(this.page.curr) {
            		result=res.data.slice(this.limit*(this.page.curr-1),this.limit*this.page.curr);
            	}else{
            	  result=res.data.slice(0,this.limit);
              }
              return {
              	"code": res.code,
              	"msg":'',
              	"count":res.count,
              	"data":result
              };
            },
            cols: [[
                //{type: "checkbox", width: 50},
                {field: 'podName',title: '名称'},
                {field: 'imgUrl',title: '镜像'},
                {field: 'podPhase', title: '状态',sort: true,templet: '#podPhaseTpl'},   
                {field: 'nameSpace', title: '命名空间', sort: true},
                {field: 'restartCount',title: '重启',sort: true},                          
                {field: 'podIp',title: 'podIp',sort: true},
                {field: 'hostIp',title:'节点IP'},  
                {field: 'nodeName',title:'节点名称',edit:true,hide:true},    
                {field: 'labes', title: '标签',edit:true,hide:true, sort: true,templet: '#TagTpl'},           
                {field: 'createTime',hide:true, title: '创建时间'},
                {title: '操作', minWidth:420, toolbar: '#currentTableBar', align: "center"}
            ]],
            //done: function(res, curr, count) {
            //    tableMerge.render(this)
            //},
            //size:'lg',
            limits: [25, 50, 100],
            limit: 25,
            page: true
        });

       table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'podLog') {
                var index = layer.open({
                    title: '日志',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xkube/podLog.html?clusterId='+clusterId+'&nameSpace='+data.nameSpace+"&podName="+data.podName,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'terminal') {
                var index = layer.open({
                    title: '终端',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xkube/podTerminal.html?clusterId='+clusterId+'&nameSpace='+data.nameSpace+"&podName="+data.podName,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });

    });
</script>
</html>